home *** CD-ROM | disk | FTP | other *** search
/ Network Support Library / RoseWare - Network Support Library.iso / apidev / sc3x03.exe / NWSYS.C < prev    next >
Text File  |  1993-04-26  |  3KB  |  88 lines

  1. //   ╔════════════════════════════════════════════════════════════════════╗
  2. //   ║                                                                    ║
  3. //   ║ module:      nwsys.c                                               ║
  4. //   ║ abstract:    This module shows how to make 3.x system calls using  ║
  5. //   ║              the F2 Shell Interface.  Obviously, it requires the   ║
  6. //   ║              NetWare Shell.                                        ║
  7. //   ║                                                                    ║
  8. //   ║ environment: NetWare 3.x v3.11                                     ║
  9. //   ║              Borland C 3.0                                         ║
  10. //   ║                                                                    ║
  11. //   ║  This software is provided as is and carries no warranty           ║
  12. //   ║  whatsoever.  Novell disclaims and excludes any and all implied    ║
  13. //   ║  warranties of merchantability, title and fitness for a particular ║
  14. //   ║  purpose.  Novell does not warrant that the software will satisfy  ║
  15. //   ║  your requirements or that the software is without defect or error ║
  16. //   ║  or that operation of the software will be uninterrupted.  You are ║
  17. //   ║  using the software at your risk.  The software is not a product   ║
  18. //   ║  of Novell, Inc. or any of subsidiaries.                           ║
  19. //   ╚════════════════════════════════════════════════════════════════════╝
  20.  
  21. #include <string.h>
  22. #include <stdlib.h>
  23. #include <dos.h>
  24. #include <fcntl.h>
  25. #include <sys/stat.h>
  26.  
  27. #include "nwsys.h"
  28.  
  29. //
  30. //  These are some helper routines we need to make system calls.  These
  31. //  are probably better off written in assembly, but I didn't want to tie
  32. //  this to a specific compiler.  
  33. //
  34.  
  35. DWORD   DWordSwap( DWORD input )
  36. {
  37.     struct _hilo{
  38.         WORD    lwlb:8;     // low word, low byte
  39.         WORD    lwhb:8;     // low word, hi  byte
  40.         WORD    hwlb:8;     // hi  word, low byte
  41.         WORD    hwhb:8;     // hi  word, hi  byte
  42.     }data;
  43.  
  44.     data = *(struct _hilo *)&input; // assign it to data
  45.  
  46.     return ((long)data.lwlb << 24) | ((long)data.lwhb << 16) |
  47.            ((long)data.hwlb << 8)  |  (long)data.hwhb;
  48. }
  49.  
  50. WORD    WordSwap( WORD input )
  51. {
  52.     struct _hilo{
  53.         WORD    lwlb:8;     // low byte
  54.         WORD    lwhb:8;     // hi  byte
  55.     }data;
  56.  
  57.     data = *(struct _hilo *)&input; // assign it to data
  58.  
  59.     return data.lwlb << 8 | data.lwhb;
  60. }
  61.  
  62. WORD    NWSystemCall(BYTE func,             // function code
  63.              void far * req,        // request buffer
  64.              WORD reqLen,           // request length
  65.              void far *rep,         // reply buffer
  66.              WORD repLen)           // reply length
  67. {
  68.     union   REGS    regs;
  69.     struct  SREGS   sregs;
  70.  
  71.     segread(&sregs);
  72.  
  73.     regs.x.ax = 0xf200 | func;      // AX = F2nn 'nn' is function code
  74.     regs.x.cx = reqLen;             // CX = request buffer length
  75.     regs.x.dx = repLen;             // DX = reply buffer length
  76.     regs.x.si = FP_OFF(req);        // SI = request buffer offset
  77.     regs.x.di = FP_OFF(rep);        // DI = reply buffer offset
  78.  
  79.     sregs.ds = FP_SEG(req);         // DS = request buffer segment
  80.     sregs.es = FP_SEG(rep);         // ES = reply buffer segment
  81.  
  82.     intdosx(®s,®s,&sregs);    // do the Int 21
  83.  
  84.     return (WORD)regs.h.al;         // return code is in AL
  85. }
  86.  
  87. 
  88.